package com.zhoutao123.article.dubbo.provider.spring;

import org.springframework.web.WebApplicationInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.HandlesTypes;
import javax.servlet.http.HttpServlet;
import java.util.Set;

/** 除了常规的web.xml 以及 @WebServlet 方式注册Servlet之外，还是可通过 ServletContainerInitializer 实现注入 */
@HandlesTypes({WebApplicationInitializer.class})
public class ServletInitializer implements ServletContainerInitializer {
  @Override
  public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {

    // 通过此方式向Servlet容器中注入Servlet拦截器，过滤器等
    ServletRegistration.Dynamic dynamic = servletContext.addServlet("s1", new HttpServlet() {});
    dynamic.setLoadOnStartup(1);





    // 注册监听器
    //    servletContext.addListener("",);

    // 注册拦截器
    //    servletContext.addFilter()

  }
}
